package net.vinote.smart.platform.service.action;

import java.sql.SQLException;

import net.vinote.smart.platform.comm.StringFunction;
import net.vinote.smart.platform.module.database.DBManager;
import net.vinote.smart.platform.module.database.bo.BizObject;
import net.vinote.smart.platform.service.util.AutoInjection;
import net.vinote.smart.platform.service.util.JSONResponse;

public class NewsInfoAction {
	@AutoInjection
	private String serialNo;

	public String publishNews() throws SQLException {
		DBManager bm = new DBManager("news_info");
		JSONResponse response = new JSONResponse();
		BizObject bo = bm.createQuery(
				new String[] { "serialNo", "publishDate" }, "serialNo=?",
				new String[] { serialNo }, null).getSingleResult();
		if (bo == null) {
			response.setSuccess(false);
			response.setMessage("记录不存在!");
		} else if (StringFunction.nullToBlank(bo.getAttribute("publishDate"))
				.length() > 0) {
			response.setSuccess(false);
			response.setMessage("不可重复发布!");
		} else {
			bo.setAttribute("publishDate", StringFunction.getTime());
			bm.updateBizObject(bo);
			response.setSuccess(true);
			response.setMessage("发布成功!");
		}
		return response.toString();
	}
}
